package cn.lunkr.sdkdemo.folder;

import static cn.lunkr.base.config.DataKey.NfFile.SELECT_PATTERN;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.DatePicker;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.res.ResourcesCompat;
import androidx.core.view.GravityCompat;
import androidx.core.view.MenuItemCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentResultListener;
import androidx.fragment.app.FragmentTransaction;

import com.facebook.drawee.generic.RoundingParams;
import com.facebook.drawee.view.SimpleDraweeView;
import com.google.android.material.navigation.NavigationView;

import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import javax.mail.event.FolderAdapter;

import cn.lunkr.base.cnf.ui.NfCenterFragment;
import cn.lunkr.base.config.Actions;
import cn.lunkr.base.config.SizeConfig;
import cn.lunkr.base.entity.PictureOptions;
import cn.lunkr.base.entity.PictureOptionsOther;
import cn.lunkr.base.entity.mail.Folder;
import cn.lunkr.base.entity.mail.MailCalendar;
import cn.lunkr.base.entity.mail.MailListFilter;
import cn.lunkr.base.entity.mail.SimpleMail;
import cn.lunkr.base.entity.pop.MailAccount;
import cn.lunkr.base.helper.MailListType;
import cn.lunkr.base.mail.util.MailUtil;
import cn.lunkr.base.mgr.MeManager;
import cn.lunkr.base.mgr.ThemeManager;
import cn.lunkr.base.net.MailNetConfig;
import cn.lunkr.base.newnet.result.CalListAccessedCalFolderResult;
import cn.lunkr.base.nf.ui.NfGlobalSearchActivity;
import cn.lunkr.base.nf.ui.NfsActivity;
import cn.lunkr.base.nf.ui.PersonalNfsActivity;
import cn.lunkr.base.nf.ui.TransferStationActivity;
import cn.lunkr.base.ui.BasicActivity;
import cn.lunkr.base.ui.DownloadedFilesActivity;
import cn.lunkr.base.ui.UploadFilesActivity;
import cn.lunkr.base.util.DateUtil;
import cn.lunkr.base.util.LogUtil;
import cn.lunkr.base.util.image.PictureLoader;
import cn.lunkr.base.view.CToolbar;
import cn.lunkr.base.view.CToolbarUtil;
import cn.lunkr.mailui.ui.Contact1sFragment;
import cn.lunkr.mailui.ui.EmailSettingActivity;
import cn.lunkr.mailui.ui.FilterPopWindow;
import cn.lunkr.mailui.ui.MailComposeActivity2;
import cn.lunkr.mailui.ui.MailFolderRemindActivity;
import cn.lunkr.mailui.ui.MailListFolderFragment;
import cn.lunkr.mailui.ui.MailsFragment;
import cn.lunkr.mailui.ui.OabActivity;
import cn.lunkr.mailui.ui.PabActivity;
import cn.lunkr.mailui.ui.calendar.ui.CalendarNewActivity;
import cn.lunkr.mailui.ui.calendar.ui.ScheduleBarFragment;
import cn.lunkr.mailui.ui.calendar.ui.ScheduleFragment;
import cn.lunkr.mailui.ui.listener.MailFolderItemClickListener;
import cn.lunkr.mailui.ui.search.SearchMailsActivity2;
import cn.lunkr.sdkdemo.R;


public class DrawerMainActivity extends BasicActivity
        implements NavigationView.OnNavigationItemSelectedListener, View.OnClickListener,
        MailsFragment.MailsFragmentListener, MailFolderItemClickListener
        , FragmentResultListener, ScheduleFragment.ScheduleListener, NfCenterFragment.NfCenterFragListener {

    private static final String TAG = "MainActivity";
    DrawerLayout drawer;
    private FolderAdapter mAdapter;
    int orderCon = 2;

    private MailsFragment mailFragment;
    private ScheduleFragment calFragment;

    private Fragment[] fragments;
    private int lastfragment;//用于记录上个选择的Fragment

    private MailListFolderFragment mFolderFragment;
    private View mailBarFolderView;
    private boolean isShowingFolderList = false;

    private FilterPopWindow mFilterPopWindow;

    private int mFilterType = MailListType.MAIL_ALL;

    private ArrayList<MailListFilter> mFilterData = new ArrayList<>();

    private TextView calTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drawer_main);
        initView();
        initData();
        initFragAction();
    }

    private void initFragments(MenuItem menuItem) {
        mailFragment = new MailsFragment();
        Contact1sFragment contractFragment = new Contact1sFragment();
        calFragment = new ScheduleFragment();
        NfCenterFragment nfCenterFragment = new NfCenterFragment(this);
        fragments = new Fragment[]{mailFragment, contractFragment, calFragment, nfCenterFragment};
        lastfragment = 0;//SPUtils.get(CalcApp.get()).getMainFragmentIndex();
        setTitle(menuItem.getTitle());
        switch (lastfragment) {
            case 0:
                getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout, mailFragment).show(mailFragment).commit();
                break;
            case 1:
                getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout, contractFragment).show(contractFragment).commit();
                break;
            case 2:
                getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout, calFragment).show(calFragment).commit();
                break;
            case 3:
                getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout, nfCenterFragment).show(nfCenterFragment).commit();
                break;
        }
    }

    private void initView() {
        calTextView = findViewById(R.id.calendar_title_tv);
        // drawer与toolbar绑定
        drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, getToolbar(), R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.addDrawerListener(toggle);
        toggle.syncState();

        // 导航与fragment绑定
        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
        MenuItem menuItem = navigationView.getMenu().getItem(lastfragment);
        menuItem.setChecked(true);
        initFragments(menuItem);
        initHeaderView(navigationView.getHeaderView(0));
    }

    private void handleMenu() {
        CToolbar toolbar = getToolbar();
        Menu menu = toolbar.getMenu();
        menu.clear();
        calTextView.setVisibility(View.GONE);
        if (lastfragment == 0) {
            if (mailFragment.getSelectMode()) {
                menu.add(1, R.id.menu_select_all, 1, cn.lunkr.mailui.R.string.select_all).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
                menu.add(1, R.id.cancel_select, 2, R.string.menu_cancel_select).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
                handleToolView(true, "", false, false); //接口实现title变更
            } else if (isShowingFolderList) {
                menu.add(1, cn.lunkr.mailui.R.id.menu_push_setting, 1, null)
                        .setIcon(cn.lunkr.mailui.R.drawable.vd_acb_mail_popwindow_setting).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
                if (mailBarFolderView == null) initMailBar();
                handleToolView(true, mailFragment.folderName(), true, true);
            } else {
                getMenuInflater().inflate(R.menu.main, menu);
                handleMenuItem(toolbar);
                MenuItem item = menu.findItem(cn.lunkr.mailui.R.id.menu_main_mail_filter_list);
                item.setIcon(mFilterType == MailListType.MAIL_ALL ? cn.lunkr.mailui.R.drawable.vd_abc_filter_a : cn.lunkr.mailui.R.drawable.vd_abc_filtered_a);
                if (mailBarFolderView == null) initMailBar();
                handleToolView(true, mailFragment.folderName(), true, true);
                mailBarFolderView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        showFolderView();
                    }
                });
            }
        } else if (lastfragment == 1) {
            if (mailBarFolderView == null) initMailBar();
            getMenuInflater().inflate(R.menu.main, menu);
            handleMenuItem(toolbar);
            handleToolView(true, "联系人", false, false);
        } else if (lastfragment == 2) {
            calTextView.setVisibility(View.VISIBLE);
            handleToolView(false, "", false, false);
            Drawable d = CToolbarUtil.getDrawable(this, cn.lunkr.mailui.R.drawable.vd_abc_pulldown);
            d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
            calTextView.setCompoundDrawables(null, null, d, null);
            calTextView.setCompoundDrawablePadding(getResources().getDimensionPixelOffset(cn.lunkr.mailui.R.dimen.dp6));
            calTextView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showSelectDate();
                }
            });
            CToolbarUtil.setTitleColor(toolbar, calTextView);
            menu.add(1, cn.lunkr.mailui.R.id.menu_calendar_go_today, 1, cn.lunkr.mailui.R.string.today).setShowAsAction(MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
            menu.add(1, cn.lunkr.mailui.R.id.menu_calendar_new, 1, cn.lunkr.mailui.R.string.xinjian).setShowAsAction(MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
        } else if (lastfragment == 3) {
            if (mailBarFolderView == null) initMailBar();
            getMenuInflater().inflate(R.menu.main, menu);
            handleMenuItem(toolbar);
            handleToolView(true, getString(R.string.item_netdisk), false, false);
        }
        CToolbarUtil.setMenuTint(this, menu);
    }


    private void handleMenuItem(CToolbar toolbar) {
        Menu menu = toolbar.getMenu();
        switch (lastfragment) {
            case 0:
                menu.findItem(R.id.menu_main_search).setVisible(true);
                menu.findItem(R.id.menu_main_mail_filter_list).setVisible(true);
                menu.findItem(R.id.menu_main_new_mail).setVisible(true);
                break;
            case 1:
            case 2:
            case 3:
                menu.findItem(R.id.menu_main_search).setVisible(false);
                menu.findItem(R.id.menu_main_mail_filter_list).setVisible(false);
                menu.findItem(R.id.menu_main_new_mail).setVisible(false);
                break;
        }
    }


    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        handleMenu();
        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.cancel_select) {
            mailFragment.onBackPressed();
            return true;
        } else if (id == R.id.menu_main_new_mail) {
            startActivity(new Intent(this, MailComposeActivity2.class));
            return true;
        } else if (id == R.id.menu_main_search) {
            Intent searchIntent = new Intent();
            searchIntent.setClass(this, SearchMailsActivity2.class);
            searchIntent.putExtra("searchViewOnToolbar", true);
            startActivity(searchIntent);
            return true;
        } else if (id == R.id.menu_main_mail_filter_list) {
            filterClick(getToolbar(), mFilterData);
            return true;
        } else if (id == cn.lunkr.mailui.R.id.menu_push_setting) {
            startActivity(new Intent(this, MailFolderRemindActivity.class));
            hideMailListFolderFragment();
            handleMenu();
            return true;
        } else if (id == cn.lunkr.mailui.R.id.menu_select_all) {
            mailFragment.selectLocalFolderAll();
            return true;
        } else if (id == cn.lunkr.mailui.R.id.menu_calendar_go_today) {
            calFragment.goToday();
            return true;
        } else if (id == cn.lunkr.mailui.R.id.menu_calendar_new) {
            Intent intent = new Intent(this, CalendarNewActivity.class);
            intent.putParcelableArrayListExtra("MyCalendarFolder", calFragment.getListCalFolderModels());
            intent.putExtra("selectedDate", calFragment.getSelectedDate());
            startActivity(intent);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();
        if (id == R.id.nav_email) {
            if (lastfragment != 0) {
                switchFragment(lastfragment, 0);
                lastfragment = 0;
            }
        } else if (id == R.id.nav_contact) {
            hideMailListFolderFragment();
            if (lastfragment != 1) {
                switchFragment(lastfragment, 1);
                lastfragment = 1;
            }
        } else if (id == R.id.nav_schedule) {
            hideMailListFolderFragment();
            if (lastfragment != 2) {
                switchFragment(lastfragment, 2);
                lastfragment = 2;
            }
            setTitle(item.getTitle());
        } else if (id == R.id.setting) {
            hideMailListFolderFragment();
            Intent intent = new Intent(this, EmailSettingActivity.class);
            startActivity(intent);
        } else if (id == R.id.nav_disk) {
            hideMailListFolderFragment();
            if (lastfragment != 3) {
                switchFragment(lastfragment, 3);
                lastfragment = 3;
            }
            setTitle(item.getTitle());
        }
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }


    private void switchFragment(int lastfragment, int index) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.hide(fragments[lastfragment]);//隐藏上个Fragment
        if (fragments[index].isAdded() == false) {
            transaction.add(R.id.frame_layout, fragments[index]);
        }
        transaction.show(fragments[index]).commitAllowingStateLoss();
        invalidateOptionsMenu();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) return;

    }

    @Override
    public void onBackPressed() {
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public void setFolderTitle(String s, String s1, ArrayList<Folder> arrayList, int i, boolean b) {
        handleMenu();
        if (mailBarFolderView != null && mailFragment.getSelectMode()) {
            TextView view = mailBarFolderView.findViewById(R.id.mails_folder_text);
            view.setText(s);
        }
    }

    @Override
    public void setFilterState(String s) {

    }

    @Override
    public void onEditPattern(boolean b) {
        handleMenu();
    }

    @Override
    public boolean onItemClick(int i, SimpleMail simpleMail, Bundle bundle) {
        return false;
    }

    @Override
    public void onMailFolderItemClick(int i, Folder folder) {
        hideMailListFolderFragment();
        ArrayList<Folder> list = new ArrayList<>();
        list.add(folder);
        mailFragment.setFolder(list);
        handleMenu();
    }

    @Override
    public void onMailFolderPopItemClick(MailAccount mailAccount) {
    }

    private void showFolderView() {
        if (mFolderFragment == null) {
            mFolderFragment = MailListFolderFragment.newInstance(mailFragment.popAccount.username,
                    mailFragment.popAccount, this);
        }
        if (!mFolderFragment.isAdded() || mFolderFragment.isHidden()) {
            isShowingFolderList = true;
            startFragment(mFolderFragment, R.id.folder_fragment, BasicActivity.TYPE_VERTICAL, false);
        } else {
            hideMailListFolderFragment();
        }
        handleMenu();
    }

    private void hideMailListFolderFragment() {
        if (mFolderFragment != null) {
            hideFragment(mFolderFragment);
            isShowingFolderList = false;
        }
    }

    public void filterClick(View v, final ArrayList<MailListFilter> filterData) {
        if (mailFragment.getSelectMode()) return;
        if (filterData == null || filterData.size() == 0) {
            return;
        }
        if (mFilterPopWindow == null)
            mFilterPopWindow = new FilterPopWindow(this, filterData, new FilterPopWindow.PopClickListener() {
                @Override
                public void onItemClick(MailListFilter pair) {
                    LogUtil.d(TAG, "mail filter" + pair.toString());
                    //更新数据
                    for (MailListFilter pair1 : filterData) {
                        if (pair == pair1) {
                            pair1.isCheck = true;
                        } else {
                            pair1.isCheck = false;
                        }
                    }
                    // 筛选
                    mFilterType = pair.type;
                    mailFragment.filterMail(pair);
                    handleMenu();
                }
            });
        mFilterPopWindow.show(v);
    }

    private void initData() {
        if (mFilterData.size() == 0) {
            MailListFilter pair = new MailListFilter(getString(cn.lunkr.mailui.R.string.all), true, MailListType.MAIL_ALL);
            mFilterData.add(pair);
            pair = new MailListFilter(getString(cn.lunkr.mailui.R.string.unread), false, MailListType.MAIL_UNREAD);
            mFilterData.add(pair);
            pair = new MailListFilter(getString(cn.lunkr.mailui.R.string.flag), false, MailListType.MAIL_MARK);
            mFilterData.add(pair);
        }
    }

    private void initFragAction() {
        getSupportFragmentManager().setFragmentResultListener("click_pab", this, this);
        getSupportFragmentManager().setFragmentResultListener("click_oab", this, this);
    }

    @Override
    public void onFragmentResult(@NonNull String requestKey, @NonNull Bundle result) {
        Intent mIntent;
        switch (requestKey) {
            case "click_oab":
                mIntent = new Intent(this, OabActivity.class);
                mIntent.putExtras(result);
                startActivity(mIntent);
                break;
            case "click_pab":
                mIntent = new Intent(this, PabActivity.class);
                startActivity(mIntent);
                break;
        }
    }

    public void setCalendarTitle(Date date) {
        calTextView.setText(DateUtil.getYearAndMonth(date));
    }

    @Override
    public void setCurrentSelectDate(Date date) {
        setCalendarTitle(date);
    }

    @Override
    public void onItemClick(int i, CalListAccessedCalFolderResult.ListAccessedCalFolderModel listAccessedCalFolderModel, MailCalendar mailCalendar) {

    }

    public void showSelectDate() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(cn.lunkr.base.R.string.calendar_sel_date);
        View view = LayoutInflater.from(this).inflate(cn.lunkr.base.R.layout.dialog_select_date, null, false);
        final DatePicker datePicker = (DatePicker) view.findViewById(cn.lunkr.base.R.id.date_picker_view);
        Calendar cal = Calendar.getInstance();
        cal.roll(Calendar.YEAR, -15);
        LogUtil.d(TAG, "start:" + DateUtil.getCalYMDHMTime(cal.getTimeInMillis()));
        datePicker.setMinDate(cal.getTimeInMillis());
        cal.roll(Calendar.YEAR, 30);
        LogUtil.d(TAG, "end:" + DateUtil.getCalYMDHMTime(cal.getTimeInMillis()));
        datePicker.setMaxDate(cal.getTimeInMillis());
        datePicker.init(calFragment.mCurrentSelectYear, calFragment.mCurrentSelectMonth, calFragment.mCurrentSelectDay, null);
        builder.setView(view);
        builder.setPositiveButton(cn.lunkr.base.R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                int year = datePicker.getYear();
                int month = datePicker.getMonth();
                int day = datePicker.getDayOfMonth();
                Calendar calendar = Calendar.getInstance();
                calendar.set(year, month, day);
                int toDayIndex = 480 / 2;
                int t = ScheduleBarFragment.getMonthSpace(year, month, day);
                calFragment.onSelectDate(year, month, day, calendar.getTimeInMillis(), toDayIndex - t);
            }
        });
        builder.setNegativeButton(cn.lunkr.base.R.string.cancel, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });
        builder.create().show();
    }

    private void initMailBar() {
        if (mailBarFolderView != null) return;
        mailBarFolderView = LayoutInflater.from(this).inflate(R.layout.layout_main_mails_toolbar_custom, null);
        TextView tv = mailBarFolderView.findViewById(R.id.mails_folder_text);
        tv.setTextColor(ThemeManager.get().getBarTitleColor());
        ImageView arrow = mailBarFolderView.findViewById(R.id.main_mails_arrows_iv);
        arrow.setImageTintList(new ColorStateList(new int[][]{new int[]{-android.R.attr.state_enabled},
                new int[]{android.R.attr.state_enabled}}, new int[]{
                ThemeManager.get().getBarTitleColor(), ThemeManager.get().getBarTitleColor()
        }));
        mailBarFolderView.findViewById(R.id.main_mails_dot_iv).setVisibility(View.GONE);
        setTitleView(mailBarFolderView);
    }

    /**
     * 四种形态
     * 待展状态 text + arrow
     * 展开状态 text + arrow 转向
     * 选择状态 text
     * 隐藏模式
     */

    private void handleToolView(boolean showText, String text, boolean showArrow, boolean clickable) {
        ImageView arrow = mailBarFolderView.findViewById(R.id.main_mails_arrows_iv);
        TextView textView = mailBarFolderView.findViewById(R.id.mails_folder_text);
        if (showText) {
            textView.setText(text);
            textView.setVisibility(View.VISIBLE);
        } else {
            textView.setVisibility(View.GONE);
        }
        if (showArrow) {
            arrow.setVisibility(View.VISIBLE);
            if (isShowingFolderList) {
                arrow.setImageDrawable(CToolbarUtil.getDrawable(this, cn.lunkr.mailui.R.drawable.vd_abc_pull_up));
            } else {
                arrow.setImageDrawable(CToolbarUtil.getDrawable(this, cn.lunkr.mailui.R.drawable.vd_abc_pulldown));
            }
        } else {
            arrow.setVisibility(View.GONE);
        }
        mailBarFolderView.setClickable(clickable);
    }

    private void initHeaderView(View view) {
        String email = MeManager.getInputEmail();
        if (StringUtils.isNotEmpty(email)) {
            TextView emailTv = view.findViewById(R.id.user_email);
            emailTv.setText(email);
            TextView nameTv = view.findViewById(R.id.user_name);
            nameTv.setText(MeManager.getDisplayName(email));
        }
        SimpleDraweeView myAvatar = view.findViewById(R.id.my_avatar);
        PictureLoader.getInstance().load(myAvatar,
                new PictureOptions.Builder().setDrawable(ResourcesCompat.getDrawable(getResources(), cn.lunkr.mailui.R.drawable.vd_abc_portrait_default, null))
                        .setUrl(MailNetConfig.getPortraitUrl(MailUtil.parseEmailFromAddress(MeManager.getInputEmail()), null, false)).build(),
                new PictureOptionsOther.Builder().setRoundingParams(RoundingParams.fromCornersRadius(SizeConfig.dp2px(this, 2))).build());
    }

    @Override
    public void toSearch(boolean b) {
        Intent intent = new Intent(this, NfGlobalSearchActivity.class);
        intent.putExtra(SELECT_PATTERN, true);
        startActivity(intent);
    }

    @Override
    public void intoFolder(boolean b, int i) {
        Intent intent = new Intent();
        intent.putExtra(SELECT_PATTERN, true); //true不选，false选择模式
        switch (i) {
            case 0:
                intent.setClass(this, NfsActivity.class);
                break;
            case 1:
                intent.setClass(this, PersonalNfsActivity.class);
                break;
            case 2:
                intent.setClass(this, UploadFilesActivity.class);
                break;
            case 3:
                intent.setClass(this, DownloadedFilesActivity.class);
                intent.putExtra("localFileDismiss", true);
                break;
            case 4:
                intent.setAction(Actions.ACTION_COLLECTION_FILE(this));
                break;
        }
        startActivity(intent);
    }

    @Override
    public void showTransPage() {
        Intent intent = new Intent(this, TransferStationActivity.class);
        startActivity(intent);
    }

    @Override
    public void getLocalFileResult(Intent intent) {
        LogUtil.i(TAG, "get fileIntent : " + intent.toString());
    }
}
